package com.ccl.iot.publics;
public class XCoreKernel {
	public static long GetUnsignedLong(long aLong){
		if (aLong < 0){
			return aLong - Long.MIN_VALUE;
		}else{
			return aLong;
		}
	}
	
	public static long SYSTICKCOUNT(){
		return GetUnsignedLong(System.currentTimeMillis());
	}
	
	public static long GetTickInterval(long aPrevTick, long aCurTick){
		if (aPrevTick < 0){
			aPrevTick = GetUnsignedLong(aPrevTick);
		}
		
		if (aCurTick < 0){
			aCurTick = GetUnsignedLong(aCurTick);
		}
		
		if (aPrevTick == aCurTick){
			return 0;
		}else if (aPrevTick < aCurTick){
			return aCurTick - aPrevTick;
		}else{
			return Long.MAX_VALUE - aPrevTick + aCurTick;
		}
	}
	
	public static long GetTickElapse(long aTick){
		return GetTickInterval(aTick, SYSTICKCOUNT());
	}
}
